﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace BMWKT
{
	public partial class Home : Form
	{
		public Home()
		{
			InitializeComponent();
			label5.Text = "欢迎使用黑猴便捷工具箱！";

			InitializeProgramAsync();
		}

		private async void InitializeProgramAsync()
		{
			if (GetBMWKInstallPathForProcess.IsGetInstallPath)
			{
				// 延时 2 秒
				await Task.Delay(2000);
			}

			// 延时 2 秒后启动 ProgramInitialization()
			ProgramInitialization();
		}

		private void OFP(string path)
		{
			if (string.IsNullOrEmpty(path)) 
			{
				label5.Text = "路径不能为空!";
				return;
			}
			new OpenFilePath(path);
		}

		private void ProgramInitialization() 
		{
			if (GetBMWKInstallPathForProcess.IsGetInstallPath)
			{
				label5.Text = "获取成功！";
				textBox1.Text = GetBMWKInstallPathForProcess.InstallPath;
				textBox2.Text = GetBMWKInstallPathForProcess.GameModPath;
				textBox3.Text = GetBMWKInstallPathForProcess.GameSavedPath;
				textBox5.Text = GetBMWKInstallPathForProcess.GameFileLastModifiedTime;
				textBox6.Text = GetBMWKInstallPathForProcess.GameFileMD5;
				button3.Enabled = true;
				button4.Enabled = true;
				button5.Enabled = true;
			}
			else
			{
				label5.Text = "获取失败，游戏未启动！";
			}
			button2.Enabled = true;
			button6.Enabled = true;
			button7.Enabled = true;
			button8.Enabled = true;
			textBox4.Text = GetBMWKInstallPathForProcess.GameConfigSavedPath;
		}

		private void button3_Click(object sender, EventArgs e)
		{
			OFP(textBox1.Text);
		}

		private void button4_Click(object sender, EventArgs e)
		{
			OFP(textBox2.Text);
		}

		private void button5_Click(object sender, EventArgs e)
		{
			OFP(textBox3.Text);
		}

		private void button6_Click(object sender, EventArgs e)
		{
			OFP(textBox4.Text);
		}

		private void button2_Click(object sender, EventArgs e)
		{
			new CreateGameSavedManageUI();
		}

		private void button8_Click(object sender, EventArgs e)
		{
			new CreateGameModManageUI();
		}

		private void button7_Click(object sender, EventArgs e)
		{
			new CreateGameConfigSavedManageUI();
		}

		private void button9_Click(object sender, EventArgs e)
		{
			new CreateAboutProgramUI();
		}

		private async void pictureBox1_Click(object sender, EventArgs e)
		{
			label5.Text = "正在刷新中……";
			await Task.Delay(2000);
			new GetBMWKInstallPathForProcess();
			ProgramInitialization();
		}

		private void pictureBox1_MouseEnter(object sender, EventArgs e)
		{
			ChangeBackColor.SetPanelNewColor(panel1);
		}

		private void pictureBox1_MouseLeave(object sender, EventArgs e)
		{
			ChangeBackColor.SetPanelOldColor(panel1);
		}
	}
}
